﻿
using System;

namespace SharePoint.Orm {
	public class SPDataContextAccessor<TSPDataContext> where TSPDataContext : SPDataContext {
		private static IContextStack<TSPDataContext> _contextStack = new UniversalContextStack<TSPDataContext>();

		public static void Push(TSPDataContext ctx) {
			ctx.Disposing = c => {
				_contextStack.Pop();
			};
			_contextStack.Push(ctx);
		}

		protected static IContextStack<TSPDataContext> ContextStack {
			get { return _contextStack; }
			set { _contextStack = value; }
		}

		public static TSPDataContext GetCurrent() {
			return _contextStack.GetCurrent();
		}
	}
}
